﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO_HealthInsurance;
namespace DAO_HealthInsurance
{
   public class DAOEmployee:ConnectDatabase
    {
        public SqlCommand Cmd;
        public DTOEmployee objEmp;
        public DataTable ListEmployee()
        {
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("listemployee", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter da = new SqlDataAdapter(Cmd);
                DataTable dt = new DataTable("EmpRegister");
                da.Fill(dt);
                CloseConnect();
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        public int InsertEmployee(DTOEmployee objEmp)
        {
            int Result = 0;
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("InsertEmployee", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@Designation", SqlDbType.VarChar, 50).Value = objEmp.EmpDesignation;
                Cmd.Parameters.Add("@Joindate", SqlDbType.DateTime).Value = objEmp.EmpJoindate;
                Cmd.Parameters.Add("@Salary", SqlDbType.Float).Value = objEmp.EmpSalary;
                Cmd.Parameters.Add("@FirstName", SqlDbType.VarChar, 50).Value = objEmp.EmpFirstName;
                Cmd.Parameters.Add("@LastName", SqlDbType.VarChar, 50).Value = objEmp.EmpLastName;
                Cmd.Parameters.Add("@UserName", SqlDbType.VarChar, 50).Value = objEmp.EmpUserName;
                Cmd.Parameters.Add("@PassWord", SqlDbType.VarChar, 20).Value = objEmp.EmpPassword;
                Cmd.Parameters.Add("@Address", SqlDbType.VarChar, 150).Value = objEmp.EmpAddress;
                Cmd.Parameters.Add("@ContactNo", SqlDbType.VarChar, 50).Value = objEmp.EmpContactNo;
                Cmd.Parameters.Add("@State", SqlDbType.VarChar, 50).Value = objEmp.EmpState;
                Cmd.Parameters.Add("@Country", SqlDbType.VarChar, 50).Value = objEmp.EmpCountry;
                Cmd.Parameters.Add("@City", SqlDbType.VarChar, 50).Value = objEmp.EmpCity;
                Cmd.Parameters.Add("@PolicySatus", SqlDbType.VarChar, 30).Value = objEmp.EmpPolicyStatus;
                Cmd.Parameters.Add("@PolicyId", SqlDbType.Int).Value = objEmp.PolicyId;
                Result = Cmd.ExecuteNonQuery();
                CloseConnect();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Result;
        }

        public int DeleteEmployee(DTOEmployee objEmp)
        {
            int Result = 0;
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("DeleteEmployee", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@EmpNo", SqlDbType.Int).Value = objEmp.EmpNo;
                Result = Cmd.ExecuteNonQuery();
                CloseConnect();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Result;

        }
        public int UpdateInFoEmp(DTOEmployee objEmp)
        {
            int Result = 0;
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("UpdateInFoEmp", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@EmpNo", SqlDbType.Int).Value = objEmp.EmpNo;
                Cmd.Parameters.Add("@Designation", SqlDbType.VarChar, 50).Value = objEmp.EmpDesignation;
                Cmd.Parameters.Add("@Joindate", SqlDbType.DateTime).Value = objEmp.EmpJoindate;
                Cmd.Parameters.Add("@Salary", SqlDbType.Float).Value = objEmp.EmpSalary;
                Cmd.Parameters.Add("@FirstName", SqlDbType.VarChar, 50).Value = objEmp.EmpFirstName;
                Cmd.Parameters.Add("@LastName", SqlDbType.VarChar, 50).Value = objEmp.EmpLastName;
                Cmd.Parameters.Add("@UserName", SqlDbType.VarChar, 50).Value = objEmp.EmpUserName;
                Cmd.Parameters.Add("@PassWord", SqlDbType.VarChar, 20).Value = objEmp.EmpPassword;
                Cmd.Parameters.Add("@Address", SqlDbType.VarChar, 150).Value = objEmp.EmpAddress;
                Cmd.Parameters.Add("@ContactNo", SqlDbType.VarChar, 50).Value = objEmp.EmpContactNo;
                Cmd.Parameters.Add("@State", SqlDbType.VarChar, 50).Value = objEmp.EmpState;
                Cmd.Parameters.Add("@Country", SqlDbType.VarChar, 50).Value = objEmp.EmpCountry;
                Cmd.Parameters.Add("@City", SqlDbType.VarChar, 50).Value = objEmp.EmpCity;
                Cmd.Parameters.Add("@PolicySatus", SqlDbType.VarChar, 30).Value = objEmp.EmpPolicyStatus;
                Cmd.Parameters.Add("@PolicyId", SqlDbType.Int).Value = objEmp.PolicyId;
                Result = Cmd.ExecuteNonQuery();
                CloseConnect();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Result;

        }

        public DataTable GetEmpById(DTOEmployee objEmp)
        {
            try
            {
                Cmd = new SqlCommand("GetEmpById", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@EmpNo", SqlDbType.Int).Value = objEmp.EmpNo;
                SqlDataAdapter da = new SqlDataAdapter(Cmd);
                DataTable dt = new DataTable("EmpRegister");
                da.Fill(dt);
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
    }
}
